﻿using UnityEngine;
using System.Collections;

public class EnemyForeny : MonoBehaviour {
    public GameObject[] waves;
    public GameObject[] planes;
    
    int index = 0;
	// Use this for initialization

        void Awake()
    {
        EmemyWave.WaveDead += SpeawnWave;
    }
	void Start () {
        SpeawnWave();

    }
	void OnDestroy()
    {
        EmemyWave.WaveDead -= SpeawnWave;
    }
    // Update is called once per frame
    float elapse = 0;
	void Update () {
        elapse += Time.deltaTime;
        if (elapse>=2)
        {
            elapse = 0;
            CreatPlane(Random.Range(0, planes.Length));
           
        }
	}
    void SpeawnWave()
    {
        Instantiate(waves[index]);
        index++;
    }

    void CreatPlane(int intdex)
    {
       GameObject go= GameObject.Instantiate(planes[intdex]);
        go.transform.position = new Vector3(Random.Range(-2f, 2f), 6.5f);
    }
    

}
